/**
 * Mocking client-server processing
 */
import $http from '../../util/axios'
let _products = []

export default {
  getProducts (parameter, cb) {
    $http.get('/static/mock/allGoods.json').then(res => {
      _products = res.data._products
    })
    if (!parameter.page || !parameter) parameter.page = 1
    if (!parameter.pageSize || !parameter) parameter.pageSize = 10
    setTimeout(() => cb(_products.slice(((parameter.page - 1) * parameter.pageSize), (parameter.page) * parameter.pageSize)), 100)
  },

  buyProducts (products, cb, errorCb) {
    setTimeout(() => {
      // 请求后台数据 成功dataList = true
      var dataList = true
      dataList ? this.getProducts() : errorCb()
    }, 100)
  }
}
